using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using IdeaBlade.EntityModel;
using IdeaBlade.Validation;
using CoProjectDF.Web.Resources;

namespace CoProjectDF.Models.Login
{

    /// <summary>
    /// Information required to register a new user.
    /// </summary>
    /// <remarks>
    /// Note that the .NET Required validation attribute is used instead of the DevForce RequiredValueVerifier attribute
    /// because the SL DataField control will automatically flag a field as required if the RequiredAttribute is present.
    /// </remarks>
    [DataContract]
    [DiscoverableType(DiscoverableTypeMode.KnownType)]
    public partial class RegistrationData : VerifiableObject
    {

        [Display(Order = 0, Name = "UserNameLabel", ResourceType = typeof(RegistrationDataResources))]
        [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(ValidationErrorResources))]
        [RegexVerifier("Name", "^[a-zA-Z0-9_]*$", ErrorMessageResourceName = "ValidationErrorInvalidUserName")]
        [StringLengthVerifier(MaxValue = 255, MinValue = 4, ErrorMessageResourceName = "ValidationErrorBadUserNameLength")]
        [DataMember]
        public string UserName
        {
            get { return _userName; }
            set
            {
                if (base.SetProperty("UserName", value, (v) => _userName = v))
                {
                    if (string.IsNullOrEmpty(FriendlyName)) { FriendlyName = value; }
                }
            }
        }

        [Display(Order = 1, Name = "FriendlyNameLabel", Description = "FriendlyNameDescription", ResourceType = typeof(RegistrationDataResources))]
        [StringLengthVerifier(MaxValue = 255, MinValue = 0, ErrorMessageResourceName = "ValidationErrorBadFriendlyNameLength")]
        [DataMember]
        public string FriendlyName
        {
            get { return _friendlyName; }
            set { base.SetProperty("FriendlyName", value, (v) => _friendlyName = v); }
        }

        [Display(Order = 2, Name = "EmailLabel", ResourceType = typeof(RegistrationDataResources))]
        [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(ValidationErrorResources))]
        [RegexVerifier("Email", @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", ErrorMessageResourceName = "ValidationErrorInvalidEmail")]
        [DataMember]
        public string Email
        {
            get { return _email; }
            set { base.SetProperty("Email", value, (v) => _email = v); }
        }

        [Display(Order = 5, Name = "SecurityQuestionLabel", ResourceType = typeof(RegistrationDataResources))]
        [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(ValidationErrorResources))]
        [DataMember]
        public string Question
        {
            get { return _question; }
            set { base.SetProperty("Question", value, (v) => _question = v); }
        }

        [Display(Order = 6, Name = "SecurityAnswerLabel", ResourceType = typeof(RegistrationDataResources))]
        [Required(ErrorMessageResourceName = "ValidationErrorRequiredField", ErrorMessageResourceType = typeof(ValidationErrorResources))]
        [DataMember]
        public string Answer
        {
            get { return _answer; }
            set { base.SetProperty("Answer", value, (v) => _answer = v); }
        }


        private string _userName;
        private string _friendlyName;
        private string _email;
        private string _question;
        private string _answer;
    }
}
